package com.ruoyi.restaurant.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.restaurant.domain.TestMain;
import com.ruoyi.restaurant.service.ITestMainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试主1Controller
 * 
 * @author ruoyi
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/testmain/show")
public class TestMainController extends BaseController
{
    @Autowired
    private ITestMainService testMainService;

    /**
     * 查询测试主1列表
     */
    @PreAuthorize("@ss.hasPermi('testmain:show:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestMain testMain)
    {
        startPage();
        List<TestMain> list = testMainService.selectTestMainList(testMain);
        return getDataTable(list);
    }

    /**
     * 导出测试主1列表
     */
    @PreAuthorize("@ss.hasPermi('testmain:show:export')")
    @Log(title = "测试主1", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestMain testMain)
    {
        List<TestMain> list = testMainService.selectTestMainList(testMain);
        ExcelUtil<TestMain> util = new ExcelUtil<TestMain>(TestMain.class);
        util.exportExcel(response, list, "测试主1数据");
    }

    /**
     * 获取测试主1详细信息
     */
    @PreAuthorize("@ss.hasPermi('testmain:show:query')")
    @GetMapping(value = "/{firstId}")
    public AjaxResult getInfo(@PathVariable("firstId") Integer firstId)
    {
        return AjaxResult.success(testMainService.selectTestMainByFirstId(firstId));
    }

    /**
     * 新增测试主1
     */
    @PreAuthorize("@ss.hasPermi('testmain:show:add')")
    @Log(title = "测试主1", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestMain testMain)
    {
        return toAjax(testMainService.insertTestMain(testMain));
    }

    /**
     * 修改测试主1
     */
    @PreAuthorize("@ss.hasPermi('testmain:show:edit')")
    @Log(title = "测试主1", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestMain testMain)
    {
        return toAjax(testMainService.updateTestMain(testMain));
    }

    /**
     * 删除测试主1
     */
    @PreAuthorize("@ss.hasPermi('testmain:show:remove')")
    @Log(title = "测试主1", businessType = BusinessType.DELETE)
	@DeleteMapping("/{firstIds}")
    public AjaxResult remove(@PathVariable Integer[] firstIds)
    {
        return toAjax(testMainService.deleteTestMainByFirstIds(firstIds));
    }

    @ApiOperation("dateCount")
    @GetMapping("/dateCount")
    public AjaxResult dateCount(TestMain testMain)
    {
        List<Map<String, Object>> listMaps  = testMainService.selectListCount(testMain);
        return AjaxResult.success(listMaps);
    }
}
